//
//  NetErrorView.m
//  WideHelp
//
//  Created by ENERGY on 2018/8/20.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "NetErrorView.h"

@implementation NetErrorView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        UIView * bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, frame.size.height)];
        bgView.backgroundColor = [UIColor whiteColor];
        [self addSubview:bgView];
        
        UIImageView * centerImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 184/WIDTH_6_SCALE, 108/WIDTH_6_SCALE, 75/WIDTH_6_SCALE)];
        centerImg.centerX = self.centerX;
        centerImg.image = [UIImage imageNamed:@"images_icon"];
        [self addSubview:centerImg];
        UILabel * titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, centerImg.bottom + 12/WIDTH_6_SCALE, SCREEN_WIDTH, 15/WIDTH_6_SCALE)];
        titleLab.text = @"网络错误，再试一下……";
        titleLab.textColor = getColor(@"676767");
        titleLab.font = DEF_FontSize_14;
        titleLab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:titleLab];
        int retryBtnH = 44/WIDTH_6_SCALE;
        UIButton * retryBtn = [[UIButton alloc] initWithFrame:CGRectMake(88/WIDTH_6_SCALE, titleLab.bottom + 28/WIDTH_6_SCALE, SCREEN_WIDTH - 176/WIDTH_6_SCALE, retryBtnH)];
        [retryBtn setTitle:@"重新加载" forState:UIControlStateNormal];
        [retryBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [retryBtn addTarget:self action:@selector(retryBtnClick) forControlEvents:UIControlEventTouchUpInside];
//        [retryBtn setBackgroundColor:getColor(greenBGColor)];
        [retryBtn setBackgroundImage:[UIImage imageNamed:@"maself_bg"] forState:UIControlStateNormal];
        retryBtn.titleLabel.font = DEF_FontSize_14;
        retryBtn.layer.cornerRadius = retryBtnH/2;
        retryBtn.layer.masksToBounds = YES;
        [self addSubview:retryBtn];
    }return self;
}

- (void)showView{
    [[UIApplication sharedApplication].delegate.window addSubview:self];
}

- (void)dismiss{
    [UIView animateWithDuration:0.5 animations:^{
        [self removeFromSuperview];
    }];
}
- (void)retryBtnClick{
    NSLog(@"重新加载");
    [self dismiss];
}
@end
